package com.weather.controller;

import com.weather.common.core.domain.R;
import com.weather.domen.DeviceDomeService;
import com.weather.pojo.entity.DeviceInfo;
import com.weather.pojo.entity.DeviceRuntimeData;
import com.weather.pojo.vo.DeviceInfoVO;
import com.weather.pojo.vo.DeviceRuntimeDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/device")
@Api(tags = "设备管理")
public class DeviceController {
    @Resource
    private DeviceDomeService deviceDomeService;

    @GetMapping("/getDeviceList")
    @ApiOperation("获取设备列表")
    public R<List<DeviceInfoVO>> getDeviceList() {
        return R.ok(deviceDomeService.getDeviceList());
    }

    @GetMapping("/getDeviceRuntimeDataById/{deviceId}")
    @ApiOperation("获取设备运行数据")
    public R<DeviceRuntimeDataVO> getDeviceRuntimeDataById(@PathVariable("deviceId") Long deviceId) {
        return R.ok(deviceDomeService.getDeviceRuntimeDataById(deviceId));
    }

    @PostMapping("/addDevice")
    @ApiOperation("添加设备")
    public R<Boolean> addDevice(@RequestBody DeviceInfo deviceInfo) {
        return R.ok(deviceDomeService.addDevice(deviceInfo));
    }

    @PutMapping("/updateDevice")
    @ApiOperation("修改设备信息")
    public R<Boolean> updateDevice(@RequestBody DeviceInfo deviceInfo) {
        return R.ok(deviceDomeService.updateDevice(deviceInfo));
    }

    @DeleteMapping("/deleteDevice/{deviceId}")
    @ApiOperation("删除设备")
    public R<Boolean> deleteDevice(@PathVariable("deviceId") Long deviceId) {
        return R.ok(deviceDomeService.deleteDevice(deviceId));
    }
}
